package com.gxa.worker.recycling.controller;

import com.gxa.core.recycling.anno.NeedToken;
import com.gxa.core.recycling.common.ExceptionCode;
import com.gxa.core.recycling.common.JsonResult;
import com.gxa.core.recycling.exception.BusinessException;
import com.gxa.worker.recycling.service.GoodsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Bei
 * @date 2021/12/2 17:59
 */
@CrossOrigin
@RestController
@RequestMapping("/goodsOrder")
@Api("商品兑换清单接口")
public class GoodsOrderController {

    @Autowired
    GoodsOrderService goodsOrderService;

    @PostMapping("/selectByDelivered")
    @ApiOperation("/查询已收货的兑换清单信息")
    @NeedToken
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rid", value = "回收员id", required = true, dataType = "long")
    })
    public Map selectByDelivered(Long rid){
        List<Map> maps = goodsOrderService.selectByDelivered(rid);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(maps);
        return jsonResult.getDataMap();
    }

    /**
     * 杨述波
     * @param id
     * @return
     */
    @PostMapping("/getOrderInfo")
    @ApiOperation("/根据商品订单查询商品兑换订单详细信息")
    @NeedToken
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "兑换订单id", required = true, dataType = "long")
    })
    public Map getOrderInfo(Long id) throws BusinessException {
        Map<String, Object> deepOrderInfo = goodsOrderService.getDeepOrderInfo(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(deepOrderInfo);
        return jsonResult.getDataMap();
    }


    //Long uid, Long gid,Long recycleId

    /**
     * 杨述波
     * @param uid
     * @param gid
     * @param recycleId
     * @return
     * @throws BusinessException
     */
    @PostMapping("/addOrder")
    @ApiOperation("/回收员---给临创用户兑换商品")
    @NeedToken
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "gid", value = "商品id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "recycleId", value = "回收员id", required = true, dataType = "long")
    })
    public Map addOrder(Long uid, Long gid,Long recycleId) throws BusinessException {
        goodsOrderService.addOrder(uid,gid,recycleId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("下单成功");
        return jsonResult.getDataMap();
    }


    /**
     * 杨述波
     * @param orderId
     * @param recycleId
     * @return
     * @throws BusinessException
     */
    @PostMapping("/finishOrder")
    @ApiOperation("/回收员---给普通用户兑换商品")
    @NeedToken
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "recycleId", value = "回收员id", required = true, dataType = "long")
    })
    public Map finishOrder(Long orderId,Long recycleId) throws BusinessException {
        goodsOrderService.finishOrderById(orderId,recycleId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("配送成功");
        return jsonResult.getDataMap();
    }



    /**
     * 杨述波
     * @param id
     * @return
     */
    @PostMapping("/getOrderByRecyclerId")
    @ApiOperation("/根据回收员id查询隶属小区的商品兑换订单")
    @NeedToken
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "回收员id", required = true, dataType = "long")
    })
    public Map getOrderByRecyclerId(Long id) throws BusinessException {
        if (id==null) {
            throw new BusinessException(ExceptionCode.NO_PEOPLE);
        }
        List<Map<String, Object>> ordersByRecyclerId = goodsOrderService.getOrdersByRecyclerId(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(ordersByRecyclerId);
        return jsonResult.getDataMap();
    }

//    /**
//     * 廖泓宇
//     * 待配送统计
//     */
//    @PostMapping("/countNoDelivered")
//    @ApiOperation("回收端首页待收货的统计")
//    @NeedToken
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "回收员id",required = true,dataType = "Long")
//    })
//    public Map countNoDelivered(Long id){
//
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setCode("200");
//        jsonResult.setData(integer);
//        return jsonResult.getDataMap();
//    }

//    /**
//     * 廖泓宇
//     * 已配送统计
//     */
//    @PostMapping("/countDelivered")
//    @ApiOperation("回收端首页已收货的统计")
//    @NeedToken
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "回收员id",required = true,dataType = "Long")
//    })
//    public Map countDelivered(Long id){
//
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setCode("200");
//        jsonResult.setData(integer);
//        return jsonResult.getDataMap();
//    }


}
